﻿namespace MicroCloud.Message.Entities
{
    /// <summary>
    /// 实体类：消息接收者
    /// </summary>
    [Description("消息接收者")]
    [ValueGenerate(ValueGenerateRule.Never, ValueGenerateMode.Snowflake)]
    [Table(nameof(MessageReceiver), Schema = TableSchemaConstants.Message)]
    public class MessageReceiver : EntityBase<long>, ICreatedTime
    {
        #region "属性"
        #region "获取或设置 消息编号"
        /// <summary>
        /// 获取或设置 消息编号
        /// </summary>
        [Column("MessageId")]
        [DisplayName("消息编号")]
        public long MessageId { get; set; }
        #endregion

        #region "获取或设置 接收者编号"
        /// <summary>
        /// 获取或设置 接收者编号
        /// </summary>
        [Column("ReceiverId")]
        [DisplayName("接收者编号")]
        public long ReceiverId { get; set; }
        #endregion

        #region "获取或设置 发送方式集合"
        private string _SendWays = string.Empty;
        /// <summary>
        /// 获取或设置 发送方式集合
        /// </summary>
        [Column("SendWays")]
        [StringMax]
        [DisplayName("发送方式：1-Internal(内部消息)、2-Email(邮件消息)、99-OAuth2(第三方平台消息)")]
        public string SendWays { get { return _SendWays; } set { _SendWays = value.ReplaceNull(); } }
        #endregion
        #region "获取或设置 阅读时间"
        /// <summary>
        /// 获取或设置 阅读时间
        /// </summary>
        [Column("LastReadTime")]
        [DisplayName("阅读时间")]
        public DateTime? LastReadTime { get; set; }
        #endregion
        #region "获取或设置 阅读方式"
        /// <summary>
        /// 获取或设置 阅读方式
        /// </summary>
        [Column("LastReadWay")]
        [DisplayName("阅读方式")]
        public MessageSendWay? LastReadWay { get; set; }
        #endregion

        #region "获取或设置 创建时间 ICreatedTime、ICreationAudited  可装载接口，在数据创建时可自动设置当前时间"
        /// <summary>
        /// 获取或设置 创建时间
        /// </summary>
        [Column("CreatedTime")]
        [DisplayName("创建时间")]
        public DateTime CreatedTime { get; set; }
        #endregion

        //只读属性
        #region "获取 是否已读"
        /// <summary>
        /// 获取 是否已读
        /// </summary>
        [NotMapped]
        public bool IsRead => LastReadTime.HasValue;
        #endregion

        //导航属性
        #region "获取或设置 消息"
        /// <summary>
        /// 获取或设置 消息
        /// </summary>
        [JsonIgnore]
        public virtual MessageEntity Message { get; set; }
        #endregion

        #endregion
    }
}